package android.zhcs.myapplication;

import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.recyclerview.widget.RecyclerView;
import androidx.recyclerview.widget.StaggeredGridLayoutManager;

import org.jetbrains.annotations.NotNull;

public class Myrec extends RecyclerView {
    public Myrec(@NonNull @NotNull Context context) {
        super(context);
    }

    public Myrec(@NonNull @NotNull Context context, @Nullable @org.jetbrains.annotations.Nullable AttributeSet attrs) {
        super(context, attrs);
    }

    public Myrec(@NonNull @NotNull Context context, @Nullable @org.jetbrains.annotations.Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    public void setAdapter(int a, int b, int c, Cal cal) {
        setLayoutManager(new StaggeredGridLayoutManager(a,RecyclerView.VERTICAL));
        super.setAdapter(new Adapter() {
            @NonNull
            @NotNull
            @Override
            public ViewHolder onCreateViewHolder(@NonNull @NotNull ViewGroup parent, int viewType) {
                return new ViewHolder(getView(c,Myrec.this.getContext())){};
            }

            @Override
            public void onBindViewHolder(@NonNull @NotNull ViewHolder holder, int position) {
                View itemView = holder.itemView;
                itemView.setTranslationX(-30);
                itemView.setAlpha(0.7f);
                itemView.animate().translationX(0).setDuration(800).start();
                itemView.animate().alpha(1).setDuration(800).start();
                cal.bix(itemView,position);
            }

            @Override
            public int getItemCount() {
                return b;
            }
        });
    }

    private View getView(int c, Context context) {
        return LayoutInflater.from(context).inflate(c,null,false);
    }
}
